var t = require("../../../../@babel/runtime/helpers/typeof"), a = getApp(), e = require("../../../../wxParse/html2json.js");

Page({
    data: {
        tabOption: [ "关注会员", "加盟店" ],
        currentIndex: 0,
        allMemberShow: !0,
        buyMemberShow: !1,
        buyList: [],
        allMember: [],
        title: "",
        m_loading: !1,
        m_allLoaded: !1,
        m_goload: !0,
        m_isLoadMore: !0,
        m_page: 1,
        m_total_page: 0,
        b_loading: !1,
        b_allLoaded: !1,
        b_goload: !0,
        b_isLoadMore: !0,
        b_page: 1,
        b_total_page: 0,
        m_total: 0,
        b_total: 0
    },
    onLoad: function(t) {
        this.checkrouter(), this.init(), this.getBuyData(), this.getMemberData(), this.getTitle();
    },
    checkrouter: function() {
        try {
            var a = function() {
                for (var t = wx.getStorageSync("yz_basic_info"), a = t.popularize_page.mini.vue_route, e = 0; e < a.length; e++) if ("ExtensionPage" == a[e]) return console.log(t.popularize_page.mini.mini_url + "跳转的路径"), 
                wx.showToast({
                    title: "未开启推广权限",
                    duration: 1e3,
                    icon: "none",
                    success: function() {
                        setTimeout(function() {
                            wx.redirectTo({
                                url: t.popularize_page.mini.mini_url
                            });
                        }, 1e3);
                    }
                }), {
                    v: void 0
                };
            }();
            if ("object" === t(a)) return a.v;
        } catch (t) {
            console.log(t);
        }
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.data.m_isLoadMore ? this.getMoreData("member", this.data.m_page) : wx.showToast({
            title: "没有更多数据",
            icon: "none"
        }), this.data.b_isLoadMore ? this.getMoreData("buy", this.data.b_page) : wx.showToast({
            title: "没有更多数据",
            icon: "none"
        });
    },
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    tabChoose: function(t) {
        var a = t.target.dataset.index || t.currentTarget.dataset.index;
        if (1 == a) this.setData({
            allMemberShow: !0,
            buyMemberShow: !1
        }); else {
            if (2 != a) return;
            this.setData({
                allMemberShow: !1,
                buyMemberShow: !0
            });
        }
    },
    init: function() {
        this.initData("member"), this.initData("buy");
    },
    getBuyData: function() {
        var t = this, o = a.getNetAddresss("plugin.member-return.frontend.ranking.index");
        o += "&page=" + this.data.b_page, a._getNetWork({
            url: o,
            success: function(a) {
                var o = a.data;
                if (1 === o.result) {
                    t.setData({
                        buyList: o.data.data
                    });
                    var n = t.data.buyList;
                    n.forEach(function(t, a) {
                        for (var o = "", n = 0; n < t.star; n++) o += "<icon class='iconfont icon-extension-stars icon-custom-undefined' style='font-size: 1.25rem; color: rgb(241, 83, 83);'></icon>";
                        t.star_count = o, t[a].star_count = e.html2json(t[a].star_count, "returnData");
                    }), t.setData({
                        buyList: n,
                        b_total_page: o.data.lastPage || 0,
                        b_total: o.data.total
                    });
                } else wx.showToast({
                    title: o.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMemberData: function() {
        var t = this, o = a.getNetAddresss("plugin.member-return.frontend.follow.index");
        o += "&page=" + this.data.m_page, a._getNetWork({
            url: o,
            success: function(o) {
                var n = o.data;
                if (1 === n.result) {
                    t.setData({
                        allMember: n.data.data
                    });
                    var i = n.data.data;
                    i.forEach(function(t, o) {
                        if (a._isTextEmpty(t.has_one_queue)) t.star_count = ""; else {
                            for (var n = "", i = 0; i < t.has_one_queue.star; i++) n += "<icon class='iconfont icon-extension-stars icon-custom-undefined' style='font-size: 1.25rem; color: rgb(241, 83, 83);'></icon>";
                            t.star_count = n, t[o].star_count = e.html2json(t[o].star_count, "returnData");
                        }
                    }), t.setData({
                        allMember: i,
                        m_total_page: n.data.lastPage,
                        m_total: n.data.total
                    });
                } else wx.showToast({
                    title: n.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreData: function(t, o) {
        var n = this;
        if ("member" == t) {
            if (this.data.m_page == this.data.m_total_page) return;
            if (this.data.m_page >= this.data.m_total_page) return void this.setData({
                m_loading: !0,
                m_allLoaded: !0
            });
            var i = this.data.m_page + 1;
            this.setData({
                m_page: i
            });
            var r = a.getNetAddresss("plugin.member-return.frontend.follow.index");
            r += "&page=" + this.data.m_page, a._getNetWork({
                url: r,
                success: function(t) {
                    var o = t.data;
                    if (1 === o.result) {
                        var i = n.data.allMember.concat(o.data.data);
                        n.setData({
                            m_loading: !1,
                            m_allLoaded: !1,
                            allMember: i
                        }), i.forEach(function(t, o) {
                            if (a._isTextEmpty(t.has_one_queue)) t.star_count = ""; else {
                                for (var n = "", i = 0; i < t.has_one_queue.star; i++) n += "<i class='iconfont icon-extension-stars icon-custom-undefined' style='font-size: 1.25rem; color: rgb(241, 83, 83);'></i>";
                                t.star_count = n, t[o].star_count = e.html2json(t[o].star_count, "returnData");
                            }
                        }), n.setData({
                            allMember: i
                        });
                    } else {
                        wx.showToast({
                            title: o.msg,
                            icon: "none"
                        });
                        var r = n.data.m_page - 1;
                        n.setData({
                            m_page: r,
                            m_loading: !0,
                            m_allLoaded: !0,
                            m_isLoadMore: !1
                        });
                    }
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        } else if ("buy" == t) {
            if (this.data.b_page == this.data.b_total_page) return;
            if (this.data.b_page >= this.data.b_total_page) return void this.setData({
                b_loading: !0,
                b_allLoaded: !0
            });
            var s = this.data.b_page + 1;
            this.setData({
                b_page: s
            });
            var l = a.getNetAddresss("plugin.member-return.frontend.ranking.index");
            l += "&page=" + this.data.b_page, a._getNetWork({
                url: l,
                success: function(t) {
                    var e = t.data;
                    if (1 === e.result) {
                        var o = n.data.buyList.concat(e.data.data);
                        n.setData({
                            b_loading: !1,
                            b_allLoaded: !1,
                            buyList: o
                        }), o.forEach(function(t) {
                            if (a._isTextEmpty(t.star)) t.star_count = ""; else {
                                for (var e = "", o = 0; o < t.star; o++) e += "<i class='iconfont icon-extension-stars icon-custom-undefined' style='font-size: 1.25rem; color: rgb(241, 83, 83);'></i>";
                                t.star_count = e;
                            }
                        }), n.setData({
                            buyList: o
                        });
                    } else {
                        wx.showToast({
                            title: e.msg,
                            icon: "none"
                        });
                        var i = n.data.b_page - 1;
                        n.setData({
                            b_page: i,
                            b_loading: !0,
                            b_allLoaded: !0,
                            b_isLoadMore: !1
                        });
                    }
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    initData: function(t) {
        "member" == t ? this.setData({
            m_loading: !1,
            m_allLoaded: !1,
            m_goload: !0,
            m_isLoadMore: !0,
            m_page: 1,
            m_total_page: 0,
            allMember: []
        }) : "buy" == t && this.setData({
            b_loading: !1,
            b_allLoaded: !1,
            b_goload: !0,
            b_isLoadMore: !0,
            b_page: 1,
            b_total_page: 0,
            buyList: []
        });
    },
    getTitle: function() {
        var t = this, e = a.getNetAddresss("plugin.member-return.frontend.set.get-name");
        a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                1 === e.result ? t.setData({
                    title: e.data.p_name
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    b64Decode: function(t) {
        var a, e, o, n, i, r, s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", l = "", d = 0;
        for (t = t.replace(/[^A-Za-z0-9\+\/\=]/g, ""); d < t.length; ) a = s.indexOf(t.charAt(d++)) << 2 | (n = s.indexOf(t.charAt(d++))) >> 4, 
        e = (15 & n) << 4 | (i = s.indexOf(t.charAt(d++))) >> 2, o = (3 & i) << 6 | (r = s.indexOf(t.charAt(d++))), 
        l += String.fromCharCode(a), 64 != i && (l += String.fromCharCode(e)), 64 != r && (l += String.fromCharCode(o));
        return l = this.utf8_decode(l);
    },
    utf8_decode: function(t) {
        for (var a, e, o, n = "", i = 0; i < t.length; ) (a = t.charCodeAt(i)) < 128 ? (n += String.fromCharCode(a), 
        i++) : a > 191 && a < 224 ? (e = t.charCodeAt(i + 1), n += String.fromCharCode((31 & a) << 6 | 63 & e), 
        i += 2) : (e = t.charCodeAt(i + 1), o = t.charCodeAt(i + 2), n += String.fromCharCode((15 & a) << 12 | (63 & e) << 6 | 63 & o), 
        i += 3);
        return n;
    },
    QueueRecord: function() {
        wx.navigateTo({
            url: "/packageB/member/enterprise/QueueRecord/QueueRecord"
        });
    }
});